package cn.usian.fallback;
import cn.usian.feign.ConsumerFeignClient;
import cn.usian.pojo.User;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class UserFeignFallback implements FallbackFactory<ConsumerFeignClient> {

    private Logger log= LoggerFactory.getLogger(UserFeignFallback.class);

    @Override
    public ConsumerFeignClient create(Throwable throwable) {
        return new ConsumerFeignClient() {
            @Override
            public User getUserById(Integer id) {
                log.error("通过id查询用户异常:{}", id, throwable);
                return new User(id,"我是托底数据Fallback",0);
            }
        };
    }
}
